<template>
	<view class="login_box">
		<view class="text_login">
			<!-- logo -->
			<image class="login_logo"  src="../../static/logo/orange.png" alt="" />
			
			<!-- 表单区域 -->
			<view class="login_phone">
				<text>手机号</text>
				<input type="text"  maxlength="11" v-model="num"/>
			</view>
			<view class="login_code">
				<text>验证码</text>
				<input type="text"  maxlength="4" v-model="codeNum"/>
				<view hover-class="touchOpacity" @click="getSvgCode()">获取验证码</view>
			</view>
			
			<!-- 登录按钮 -->
			<view class="login_but" hover-class="touchOpacity" >
				<text space="ensp" @click="login()">登    录</text> 
			</view>
		</view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				num:'',
				codeNum:'',
				code:null
			}
		},
		methods: {
			//获取验证码
			getSvgCode(){
				this.$http({
					url:'sms',
					data:{
						phone:this.num
					}
				}).then(res=>{
					console.log(res);
					this.code=res.list.code
				})
			},
			//登录
			login(){
				// console.log(this.num);
				if(this.codeNum==this.code){
				this.$http({
					url:'smslogin',
					data:{
						phone:this.num
					},
					method:'post'
				}).then(res=>{
					console.log(res);
					if(res.code==200){
					this.$tool.tip('登录成功')
					setTimeout(()=>{
						// console.log(111);
						//把用户信息存到本地
						uni.setStorageSync('userInfo',res.list)
						uni.setStorageSync('token',res.list.token)
						uni.switchTab({
							url:"../user/user"
						})
					},1000)
					}
				})
				}
			}
		}
}
</script>

<style>
	/* 引入样式 */
	@import url("@/static/css/textlogin.css");
</style>
